package cn.hh.redis.util;

import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @Author huangh
 * @date 2021/11/23
 * @Description:
 */
public class OrderCertAbility {

    private final static String pathUrl = "https://proc.fj.189.cn/uop-web/cert/contents/order_cert_ability.html";
    private final static String key = "29BC0CB57D59A7872FE00F06";
    private final static String authCode = "certAbility";
    private final static String appCode = "FJWT";

    public static String getRealUrl(Map<String,Object> param) throws Exception {
        String resUrl = "";
        String openNo = StrUtil.toString(param.get("openNo"));;
        String custName = StrUtil.toString(param.get("custName"));;
        String custCertNo = StrUtil.toString(param.get("custCertNo"));
        String jumpPage = StrUtil.toString(param.get("jumpPage"));
        //String date = StrUtil.toString(param.get("date"));
        String bizData = "";

        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        String dateStr = sdf.format(new Date());

        Map<String,Object> bizDateMap = new LinkedHashMap<>();
        bizDateMap.put("custName",custName);
        bizDateMap.put("custCertNo",custCertNo);
        bizDateMap.put("jumpPage",jumpPage);
        bizDateMap.put("date",dateStr);
        bizData = JSONUtil.toJsonStr(bizDateMap);
        //String bizDateDec = AESUtil.encrypt(bizData, key);
        String bizDateDec =  UopThreeDES.getInstance().encrypt(bizData, key);


        //?authCode=certAbility&appCode=FJWT
        resUrl = pathUrl + "?authCode=" + authCode + "&appCode=" + appCode
                +"&openNo=" +openNo + "&bizData=" + bizDateDec;

        return resUrl;
    }

    public static void main(String[] args) throws Exception {
        Map<String,Object> param = new LinkedHashMap<>();


        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        String dateStr = sdf.format(new Date());
        param.put("openNo","FJ20211123213123123");
        //param.put("custName","黄浩");
        //param.put("custCertNo","350104199404234957");
        param.put("custName","");
        param.put("custCertNo","");
        param.put("jumpPage","http://localhost:8080/user/index");
        //param.put("date",dateStr);
//        param.put("","");
//        param.put("","");
        String url = OrderCertAbility.getRealUrl(param);
        System.out.println(url);

    }



}
